import { makeActions, eventHub } from "@common/utils/eventActionsMaker";

export const events = {
  Remote: {
    Invoke: (() => {
      const { off, on } = makeActions<{
        receiverId: string | "plugin";
        eventName: string;
        data: unknown;
      }>("remote.invoke");
      return { off, on };
    })(),
    Accept: (() => {
      const { off, on, emit } = makeActions<{
        eventName: string;
        data: unknown;
        sender: string;
      }>("remote.accept");
      return { off, on, emit };
    })(),
  },
};

events.Remote.Accept.on(({ eventName, data, sender }) => {
  eventHub.emit(eventName, data, eventName, sender);
});
